﻿using MES.Desktop.DataAccess;
using MES.Desktop.Entities;
using MES.Desktop.IDataAccess;
using MES.Desktop.IService;
using MES.Desktop.Service;
using MES.Desktop.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;
using Prism.Unity;
using System.Configuration;
using System.Data;
using System.Windows;

namespace MES.Desktop
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        GlobalValues globalValues = new GlobalValues();
        public App()
        {
            globalValues.ServerHost = System.IO.File.ReadAllText(".\\server");
            globalValues.AuthServerHost = System.IO.File.ReadAllText(".\\authServer");
        }

        protected override Window CreateShell()
        {
            return Container.Resolve<MainView>();
        }
        protected override void InitializeShell(Window shell)
        {
            base.InitializeShell(shell);

            Container.Resolve<IRegionManager>()
                .RequestNavigate("MainRegion", "WorkbenchesView");
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<GlobalValues>(() => globalValues);
            containerRegistry.RegisterDialogWindow<DialogWindow>();
            containerRegistry.RegisterDialog<LoginView>();
            containerRegistry.Register<IFileService, FileService>();
            containerRegistry.Register<IFileAccess, FileAccess>();
            containerRegistry.Register<IUserService, UserService>();
            containerRegistry.Register<IUserAccess, UserAccess>();
            containerRegistry.Register<IMenuService, MenuService>();
            containerRegistry.Register<IMenuAccess, MenuAccess>();
            containerRegistry.Register<IAuthServer, AuthServer>();
            containerRegistry.Register<IAuthAccess, AuthAccess>();
            containerRegistry.Register<IPostService, PostService>();
            containerRegistry.Register<IPostAccess, PostAccess>();
            containerRegistry.Register<IDepartService, DepartService>();
            containerRegistry.Register<IDepartAccess, DepartAccess>();
            containerRegistry.Register<IFuncService, FuncService>();
            containerRegistry.Register<IFuncAccess, FuncAccess>();
            containerRegistry.Register<IRoleService, RoleService>();
            containerRegistry.Register<IRoleAccess, RoleAccess>();
            containerRegistry.Register<IMaterialService, MaterialService>();
            containerRegistry.Register<IMaterialAccess, MaterialAccess>();
            containerRegistry.RegisterForNavigation<WorkbenchesView>();
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new DirectoryModuleCatalog
            {
                ModulePath = Environment.CurrentDirectory + "\\Modules"
            };
            //return base.CreateModuleCatalog();
        }
    }

}
